package com.example.bozai.util;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@Component
public class HttpUtil {

    //发送post请求
    public  static  JSONObject postRequest(String url , String jsonBody,String token) {
        HttpHeaders headers=new HttpHeaders();
        RestTemplate restTemplate = new RestTemplate();
        if (null!=token){
            headers.add("Authorization",token);
        }
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> requestEntity = new HttpEntity<>(jsonBody, headers);
        ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
        JSONObject result = JSONObject.parseObject(response.getBody());
        return result;
    }


}
